import { ProFieldFC } from '@ant-design/pro-components';
import React from 'react';
import SfwAmapLocationSelect from '../../../form/SfwAmapLocationSelect';

/**
 * 代码片段组件 这个组件为了显示简单的配置，复杂的请使用更加重型的组件
 */
const FieldSfwAmapLocationSelect: ProFieldFC<{
  text: any;
}> = (props, ref) => {
  const { text, mode, fieldProps } = props;
  const { value, onChange } = fieldProps;

  if (mode === 'read') {
    return (
      <SfwAmapLocationSelect ref={ref} {...fieldProps} value={value} readOnly>
        {text}
      </SfwAmapLocationSelect>
    );
  }
  if (mode === 'edit' || mode === 'update') {
    return (
      <SfwAmapLocationSelect
        ref={ref}
        {...fieldProps}
        value={value}
        onChange={onChange}
      />
    );
  }
  return null;
};

export default React.forwardRef(FieldSfwAmapLocationSelect);
